<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2018/11/8
 * Time: 11:40
 */
namespace app\admin\controller;
use think\Db;
class Member extends Base
{
    /*
     * 用户首页数据
     */
    public function index(){
        if(request()->isAjax ()){
            extract(input());
            $map = [];
            if(isset($key)&&$key!="")
            {
                $map['user_username'] = ['like',"%" . $key . "%"];
            }
            if(isset($start)&&$start!=""&&isset($end)&&$end=="")
            {
                $map['user_time'] = ['>= time',$start];
            }
            if(isset($end)&&$end!=""&&isset($start)&&$start=="")
            {
                $map['user_time'] = ['<= time',$end];
            }
            if(isset($start)&&$start!=""&&isset($end)&&$end!="")
            {
                $map['user_time'] = ['between time',[$start,$end]];
            }
            $Nowpage = input('page') ? input('page'):1;
            $limits = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::name('u_user')->count();
            $lists = Db::name('u_user')
                ->where($map)
                ->field('user_id,user_username,user_image,user_rel_name,user_id_number,user_auth_status,user_time')
                ->page($Nowpage,$limits)
                ->order('user_time desc')
                ->select();
            return json(['code'=>220,'msg'=>'','count'=>$count,'data'=>$lists]);
        }
        return $this->fetch('member/index');
    }

    /*
     * 用户认证
     */
    public function agreeUser(){
        extract(input());
        $res = Db::name('u_user')
            ->where('user_id',$id)
            ->update(['user_auth_status'=>$type,'user_update_time'=>date('Y-m-d H:i:s')]);
        if($res){
            return json(['code'=>200,'msg'=>'审核成功']);
        }else{
            return json(['code'=>100,'msg'=>'审核失败']);
        }
    }

    /*
     * 删除用户
     */
    public function memberDel(){
        $res = Db::name('u_user')
            ->where('user_id',input('id'))
            ->delete();
        if($res){
            return json(['code'=>200,'msg'=>'删除成功']);
        }else{
            return json(['code'=>100,'msg'=>'删除失败']);
        }

    }
}